package com.swak.vertx.protocol.im;

import com.swak.utils.StringUtils;

/**
 * 处理心跳
 * 
 * @author 618lf
 */
public class HeartbeatHandler implements io.vertx.core.Handler<ImContext> {

	private final String Ping = "Ping";
	private final String Pong = "Pong";

	@Override
	public void handle(ImContext event) {
		String heartbeat = event.request().getBodyAsString();
		if (StringUtils.isNotBlank(heartbeat) && Ping.equals(heartbeat)) {
			event.response().out(Pong);
		} else {
			event.next();
		}
	}

	public static HeartbeatHandler hander() {
		return new HeartbeatHandler();
	}
}